import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import 'element-ui/lib/theme-chalk/index.css'

import ElementUI from 'element-ui'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import Cookies from 'js-cookie'
import '@/styles/index.scss' // global css
import App from './App'
import store from './store'
import router from './router'
import '@/icons' // icon
import '@/permission' // permission control
import { Message } from 'element-ui'
import _ from 'lodash'
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;
// 拖拽组件注册
import VueDragResize from 'vue-drag-resize'
Vue.component('vue-drag-resize', VueDragResize)
// 自定义指令导入
import onlyNumber from '@/directive/elInputNumber';
Vue.use(onlyNumber)
// import applicationUserManager from '@/auth/applicationusermanager';
// console.log(applicationUserManager);
// debugger;
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
//
//vue 全局方法
import {parseTime} from '@/utils/index';
Vue.prototype.$parseTime = parseTime;
import request from '@/utils/request'
Vue.prototype.$request = request;
Vue.config.productionTip = false;
Vue.prototype._ = _;
Vue.prototype.$cookie = Cookies;
Vue.prototype.erroMessageShow = function(error){
  Message.error('程序或服务器异常，错误信息：'+error)
}
Vue.prototype.defaultHeadImg = "https://cdn.shan-niang.com/shops/mendiantouxiang.png";
Vue.prototype.validForbid = function (value, number = 255) {
  value = value.replace(/[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘’，。、]/g, '').replace(/\s/g, "");
  if (value.length >= number) {
    this.$message({
      type: "warning",
      message: `输入内容不能超过${number}个字符`
    });
  }
  return value;
};
Vue.prototype.validNumber = function (value, number = 255) {
  if(!value){
    return 0
  }
  let str = value.toString();
  str = str.replace(/[^0-9]/g,'');
  return Number(str);
};
/*实时获取sessionStorage的值*/
Vue.prototype.resetSetItem = function (key, newVal) {
  if (key === 'templateId') {
      // 创建一个StorageEvent事件
      var newStorageEvent = document.createEvent('StorageEvent');
      const storage = {
          setItem: function (k, val) {
              sessionStorage.setItem(k, val);

              // 初始化创建的事件
              newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null);

              // 派发对象
              window.dispatchEvent(newStorageEvent)
          }
      }
      return storage.setItem(key, newVal);
  }
}
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
